#pragma once
#include "ieventagent.h"


//this object should be deleted by target.
//target class define a method: void onMessage(Ts source, Targument args).
//source class defined register(IEventArgent) and unregister(IEventArgent) method for registering
//or unregister event handler.
template<typename Ts, typename Tt, typename Targ>
class EventAgent: public IEventAgent<Targ>
{
	
	//field
private:
	Ts* source;
	Tt* target;

public:
	

	EventAgent(Ts* source, Tt* target)
		:source(source), target(target)
	{
		source->registerEvent(this);
	}
	void clearSource()
	{
		source = NULL;
	}
	virtual ~EventAgent(void)
	{
		if(source != NULL)
		{
			source->unregisterEvent(this);
		}
	}
	void fireEvent(Targ * args)
	{
		target->onMessage(source, args);
	}
};
